home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / ginclude / va-mips.h < prev    next >
C/C++ Source or Header  |  1995-02-24  |  4KB  |  118 lines

  1. /* ---------------------------------------- */
  2. /*           VARARGS  for MIPS/GNU CC       */
  3. /*                                          */
  4. /*                                          */
  5. /*                                          */
  6. /*                                          */
  7. /* ---------------------------------------- */
  8.  
  9.  
  10. /* These macros implement varargs for GNU C--either traditional or ANSU.  */
  11.  
  12. /* Define __gnuc_va_list.  */
  13.  
  14. #ifndef __GNUC_VA_LIST
  15. #define __GNUC_VA_LIST
  16. typedef char * __gnuc_va_list;
  17. #endif /* not __GNUC_VA_LIST */
  18.  
  19. /* If this is for internal libc use, don't define anything but
  20.    __gnuc_va_list.  */
  21. #if defined (_STDARG_H) || defined (_VARARGS_H)
  22.  
  23. /* In GCC version 2, we want an ellipsis at the end of the declaration
  24.    of the argument list.  GCC version 1 can't parse it.  */
  25.  
  26. #if __GNUC__ > 1
  27. #define __va_ellipsis ...
  28. #else
  29. #define __va_ellipsis
  30. #endif
  31.  
  32. #if __mips>=3
  33. #define __va_rounded_size(__TYPE)  \
  34.   (((sizeof (__TYPE) + 8 - 1) / 8) * 8)
  35. #else
  36. #define __va_rounded_size(__TYPE)  \
  37.   (((sizeof (__TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
  38. #endif
  39.  
  40. /* Get definitions for _MIPS_SIM_ABI64 etc.  */
  41. #ifdef _MIPS_SIM
  42. #include <sgidefs.h>
  43. #endif
  44.  
  45. #ifdef _STDARG_H
  46. #if defined(_MIPS_SIM) && (_MIPS_SIM == _MIPS_SIM_ABI64)
  47. #define va_start(__AP, __LASTARG)                    \
  48.   (__AP = __builtin_next_arg (__LASTARG) - 64                \
  49.    + (__builtin_args_info (2) > 8 ? 64 : __builtin_args_info(2) * 8))
  50. #else
  51. #define va_start(__AP, __LASTARG) \
  52.   (__AP = (__gnuc_va_list) __builtin_next_arg (__LASTARG))
  53. #endif
  54.  
  55. #else
  56. #define va_alist  __builtin_va_alist
  57. #if __mips>=3
  58. /* This assumes that `long long int' is always a 64 bit type.  */
  59. #define va_dcl    long long int __builtin_va_alist; __va_ellipsis
  60. #else
  61. #define va_dcl    int __builtin_va_alist; __va_ellipsis
  62. #endif
  63. /* Need alternate code for _MIPS_SIM_ABI64, but don't use that symbol
  64.    because it may not be defined.  */
  65. #if defined(_MIPS_SIM) && (_MIPS_SIM == _MIPS_SIM_ABI64)
  66. #define va_start(__AP)                            \
  67.   (__AP = __builtin_next_arg () - 64                    \
  68.    + (__builtin_args_info (2) > 8 ? 64 : __builtin_args_info(2) * 8))
  69. #else
  70. #define va_start(__AP)  __AP = (char *) &__builtin_va_alist
  71. #endif
  72. #endif
  73.  
  74. #ifndef va_end
  75. void va_end (__gnuc_va_list);        /* Defined in libgcc.a */
  76. #endif
  77. #define va_end(__AP)    ((void)0)
  78.  
  79. /* We cast to void * and then to TYPE * because this avoids
  80.    a warning about increasing the alignment requirement.  */
  81. /* The __mips>=3 cases are reversed from the 32 bit cases, because the standard
  82.    32 bit calling convention left-aligns all parameters smaller than a word,
  83.    whereas the __mips>=3 calling convention does not (and hence they are
  84.    right aligned).  */
  85. #if __mips>=3
  86. #ifdef __MIPSEB__
  87. #define va_arg(__AP, __type)                                    \
  88.   ((__type *) (void *) (__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \
  89.                      + __va_rounded_size (__type))))[-1]
  90. #else
  91. #define va_arg(__AP, __type)                                    \
  92.   ((__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8)    \
  93.              + __va_rounded_size (__type))),        \
  94.    *(__type *) (void *) (__AP - __va_rounded_size (__type)))
  95. #endif
  96.  
  97. #else /* not __mips>=3 */
  98.  
  99. #ifdef __MIPSEB__
  100. /* For big-endian machines.  */
  101. #define va_arg(__AP, __type)                    \
  102.   ((__AP = (char *) ((__alignof__ (__type) > 4            \
  103.               ? ((int)__AP + 8 - 1) & -8        \
  104.               : ((int)__AP + 4 - 1) & -4)        \
  105.              + __va_rounded_size (__type))),        \
  106.    *(__type *) (void *) (__AP - __va_rounded_size (__type)))
  107. #else
  108. /* For little-endian machines.  */
  109. #define va_arg(__AP, __type)                            \
  110.   ((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4        \
  111.                       ? ((int)__AP + 8 - 1) & -8        \
  112.                       : ((int)__AP + 4 - 1) & -4)        \
  113.                      + __va_rounded_size(__type))))[-1]
  114. #endif
  115. #endif
  116.  
  117. #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */
  118.